﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a parameter for an &lt;object&gt; tag.
    /// </summary>
    [Serializable]
    [Standalone]
    public class Param : Element {
        /// <summary>
        /// Represents the possible choices for the ValueType attribute.
        /// </summary>
        public enum ValueTypeChoices {
            /// <summary>
            /// The value is passed as a string.
            /// </summary>
            Data,
            /// <summary>
            /// The value is a URI to a resource where run-time values are
            /// stored.
            /// </summary>
            Ref,
            /// <summary>
            /// The value is the ID of another &lt;object&gt;.
            /// </summary>
            Object
        }
        private string _name;
        private string _type;
        private string _value;
        private ValueTypeChoices? _valuetype;

        /// <summary>
        /// Constructs a new Param element with the given name and value.
        /// </summary>
        /// <param name="name">The name of this paramater.</param>
        /// <param name="value">The value of this parameter.</param>
        public Param(string name, string value) {
            _name = name;
            _value = value;
        }

        /// <summary>
        /// Determines the name of this parameter.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Determines the type of values found at the URL specified by Value.
        /// </summary>
        public string Type {
            get { return _type; }
            set { _type = value; }
        }

        /// <summary>
        /// Determines the value of the paramater.
        /// </summary>
        public string Value {
            get { return _value; }
            set { _value = value; }
        }

        /// <summary>
        /// Determines the type of the Value parameter.
        /// </summary>
        public ValueTypeChoices? ValueType {
            get { return _valuetype; }
            set { _valuetype = value; }
        }

        /// <summary>
        /// Gets a formatted string of all child elements of this element.
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's child
        /// data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _name, "name");
            AttributeWriter.Write(sb, _type, "type");
            AttributeWriter.Write(sb, _value, "value");
            AttributeWriter.Write(sb, _valuetype, "valuetype", true);
        }
    }
}
